package spring.in.action.chapter_03.express;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource("classpath:spring/in/action/chapter_03/Express.properties")
public class ExpressConfig
{
    @Autowired
    Environment env;

    @Bean
    public BankDisc disc1()
    {
        return new BankDisc(env.getProperty("disc.title"), env.getProperty("disc.artist"));
    }

    @Bean
    public BankDisc disc2()
    {
        return new BankDisc(env.getProperty("disc.title", "没有标题"),
                env.getProperty("disc.artist", "没有作者"));
    }

    @Bean
    public BankDisc disc3(@Value("${disc.title}") String pTitle,
            @Value("${disc.artist}") String pArtist)
    {
        return new BankDisc(pTitle, pArtist);
    }

    /***
     * 为了使用 占位符，必须使用，但是在junit中报错，等实际项目中再试一下
     * 1、@Bean PropertySourcesPlaceholderConfigurer
     * 2、<context:property-placeholder location="classpath:${env}/resources.properties"/>
     * 3、<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
           <list>  
              <value>classpath:/spring/include/jdbc-parms.properties</value>  
              <value>classpath:/spring/include/base-config.properties</value>  
            </list>  
        </property>  
    </bean>  
     */
}
